package com.ufo.time;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateFormatters {
    public static void main(String[] args){
        //旧的API
        String formatText="yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sFormat=new SimpleDateFormat(formatText);
        System.out.println("SimpleDateFormat: "+sFormat.format(new Date()));

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(formatText);
        //有两种调用方式
        System.out.println("dateTimeFormatter: "+dateTimeFormatter.format(LocalDateTime.now()) + " or "+ LocalDateTime.now().format(dateTimeFormatter));

        //LocalDate have no hour , so can not format
        //System.out.println("  or for LocalDate:"+ LocalDate.now().format(dateTimeFormatter));

        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        System.out.println(" for LocalDate:"+ LocalDate.now().format(dateFormatter));
    }
}
